import Popup from "@arcgis/core/widgets/Popup";
import PopupTemplate from "@arcgis/core/PopupTemplate";
import { map, mapView } from "@/api/map";
import {
  sjz_road_layer,
  police_layer,
  factory_layer,
  hospital_layer,
  fire_station_layer,
  river_line_layer,
  sjz_county_layer,
  river_area_layer,
} from "@/api/featuresLayers";
//点击查询
export const showFeatureInfo = () => {
  mapView.popup = new Popup({
    dockEnabled: true,
    dockOptions: {
      buttonEnabled: false,
      breakpoint: false,
      // position: "top-right"
    },
  });
  // //给每一个要素图层增加该属性值
  let template = new PopupTemplate({
    title: "{name}",
    outFields: ["*"],
    content: [
      //    一般显示方法
      {
        type: "fields",
        fieldInfos: [
          {
            fieldName: "name",
            label: "名称",
          },
        ],
      },
    ],
  });
  let RoadTemplate = new PopupTemplate({
    title: "{name}",
    content: [
      {
        type: "fields",
        fieldInfos: [
          {
            fieldName: "name",
            label: "名称",
          },
          {
            fieldName: "type",
            label: "道路类型",
          },
        ],
      },
    ],
  });
  let FireStationTemplate = new PopupTemplate({
    title: "{name}",
    content: [
      {
        type: "fields",
        fieldInfos: [
          {
            fieldName: "name",
            label: "名称",
          },
          {
            fieldName: "Region",
            label: "所在地区",
          },
          {
            fieldName: "X",
            label: "经度",
          },
          {
            fieldName: "Y",
            label: "纬度",
          },
        ],
      },
    ],
  });
  let HospitalTemplate = new PopupTemplate({
    title: "{name}",
    content: [
      {
        type: "fields",
        fieldInfos: [
          {
            fieldName: "name",
            label: "名称",
          },
          {
            fieldName: "Region",
            label: "所在地区",
          },
          {
            fieldName: "X",
            label: "经度",
          },
          {
            fieldName: "Y",
            label: "纬度",
          },
        ],
      },
    ],
  });
  let FactoryTemplate = new PopupTemplate({
    title: "{name}",
    outFields: ["*"],
    fieldInfos: [
      {
        fieldName: "name",
        visible: true,
        label: "名称",
      },
      {
        fieldName: "Region",
        visible: true,
        label: "所在地区",
      },
      {
        fieldName: "X",
        visible: true,
        label: "经度",
      },
      {
        fieldName: "Y",
        visible: true,
        label: "纬度",
      },
      {
        fieldName: "relationships/0/NH3",
        visible: true,
        label: "液氨",
      },
      {
        fieldName: "relationships/0/Cl2",
        visible: true,
        label: "氯气",
      },
      {
        fieldName: "relationships/0/Hcl",
        visible: true,
        label: "浓盐酸",
      },
    ],
    content: [
      {
        type: "fields",
      },
      {
        type: "media", // MediaContentElement
        mediaInfos: [
          {
            title: "<b>化学品信息</b>",
            type: "pie-chart",
            caption: "单位：吨",
            value: {
              fields: [
                "relationships/0/NH3",
                "relationships/0/Cl2",
                "relationships/0/Hcl",
              ],
              normalizeField: null,
              // tooltipField: "name"
            },
          },
        ],
      },
    ],
  });
  sjz_county_layer.popupTemplate = template;
  river_area_layer.popupTemplate = template;
  river_line_layer.popupTemplate = template;
  police_layer.popupTemplate = template;
  sjz_road_layer.popupTemplate = RoadTemplate;
  fire_station_layer.popupTemplate = FireStationTemplate;
  factory_layer.popupTemplate = FactoryTemplate;
  hospital_layer.popupTemplate = HospitalTemplate;
};
